let OSS = require('ali-oss')
 
let client = new OSS({
    region: 'oss-cn-shanghai',
    //云账号AccessKey有所有API访问权限，建议遵循阿里云安全最佳实践，部署在服务端使用RAM子账号或STS，部署在客户端使用STS。
    accessKeyId: 'LTAI5tNxiTYN3b9BNsqVFR52',
    accessKeySecret: 'VfUyjt9SnYLTK4oQT2D4D1lSXTTAJN',
    bucket: 'ytfacetest',
    endpoint: 'oss-cn-shanghai.aliyuncs.com',
    secure: true
})
 
export const put = async (ObjName, fileUrl) => {  
  try {    
    let result = await client.put(`${ObjName}`, fileUrl)    
       
    return result  
  } catch (e) {    
   console.log(e)  
  }
}
 
// 上传成功之后，转换真实的地址
export const signatureUrl= async (ObjName) => {    
  try {        
    let result = await client.signatureUrl(`${ObjName}`)    
    return result  
  } catch (e) {    
    console.log(e)  
  }
}
 
export const getFileNameUUID = () => {  
  function rx() {    
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)  
  }  
  return `${+new Date()}_${rx()}${rx()}`
}


 // 随机生成名称
 export const generateUniqueFileName = () => {
    let chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    let fileName = '';
    for (let i = 0; i < 26; i++) {
      fileName += chars.charAt(Math.floor(Math.random() * chars.length));
    }
    // console.log(fileName)
    return fileName;
  }

  